﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="JDML Consulting Ltd." file="ModelTypeTests.cs">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.ComponentModel.Modelling
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using TestAssets;
    using DescriptionAttribute = System.ComponentModel.DescriptionAttribute;

    [TestClass]
    public class ModelTypeTests
    {
        public class TestAttributes
        {
            public static Attribute TestObjectBaseCategory = new CategoryAttribute("Test");
            public static Attribute TestObjectBaseDescription = new DescriptionAttribute("Test Object Base");
            public static Attribute TestObjectDescendentDescription = new DescriptionAttribute("Test Object Descendent");
        }
        
        [Category("Base")]
        [MetadataType(typeof(TestObjectBaseMetadata))]
        [InheritedAllowMultiple("Base")]
        public class TestObjectBase
        {
            [Description]
            public virtual string VirtualProperty { get; set; }
        }

        [Description("Test Object Base")]
        public class TestObjectBaseMetadata
        {
        }
        
        [Description("Test Object Descendent")]
        [Category("Descendent")]
        [InheritedAllowMultiple("Descendent")]
        public class TestObjectDescendent : TestObjectBase
        {
            [Description("DescendentVirtualProperty")]
            public override string VirtualProperty
            {
                get { return base.VirtualProperty; }
                set { base.VirtualProperty = value; }
            }
        }

        [Description("Test Object Descendent Descendent")]
        [InheritedAllowMultiple("Descendent Descendent")]
        public class TestObjectDescendentDescendent : TestObjectDescendent
        {
            [Description("DescendentDescendentVirtualProperty")]
            public override string VirtualProperty
            {
                get { return base.VirtualProperty; }
                set { base.VirtualProperty = value; }
            }
        }

        [TestMethod]
        public void Should_Order_Attributes_In_Hierarchy()
        {
            var metamodelType = MetaModel.Default.GetOrCreateType(typeof(TestObjectDescendentDescendent));
            if (metamodelType.Attributes.Count > 0)
            {
                
            }
        }
        
        [TestMethod]
        public void Should_Contain_Properties()
        {
            var metadata = MetaModel.Default.GetOrCreateType(typeof(TestObjectBase));
            Assert.AreEqual(1, metadata.Properties.Count);
            Assert.AreEqual("VirtualProperty", metadata.Properties[0].Name);
            Assert.AreEqual(metadata.Properties[0], metadata.Properties["VirtualProperty"]);
        }

        [TestMethod]
        public void Should_Contain_Attributes_Associated_Via_MetadataTypeAttribute()
        {
            var metadata = MetaModel.Default.GetOrCreateType(typeof(TestObjectBase));
            Assert.IsTrue(metadata.Attributes.Contains(TestAttributes.TestObjectBaseDescription));
        }

        [TestMethod]
        public void Should_Order_Attributes_Associated_Via_MetadataTypeAttribute_After_Direct_Attributes()
        {
            var metadata = MetaModel.Default.GetOrCreateType(typeof(TestObjectBase));
            Assert.AreEqual(TestAttributes.TestObjectBaseDescription, metadata.Attributes[3]);
        }
    }
}
